<template>
    <button
            class="btn btn-default"
            v-bind:class="{'btn-success' : followed}"
            v-text="text"
            v-on:click="follow"
    ></button>
</template>

<script>
    export default {
        props:['question'],
        mounted() {
            var self = this;
            axios.post('/api/question/follower',{'question':this.question}).then(response => {
                self.followed = response.data.followed;
            })
        },
        data(){
            return {
                followed: false,
            }
        },
        methods:{
            follow(){
                var self = this;
                axios.post('/api/question/follow',{'question':this.question}).then(response => {
                    self.followed = response.data.followed;
                })
            }
        },
        computed: {
            text(){
                return this.followed ? '已关注' : '关注问题';
            }
        }
    }
</script>